package com.jewelry.common.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;

/**
 * 日志管理对象
 * @author yangfeng
 *
 */
public class LogManager {
	
	public static void init(String logConfigFile){
		System.out.println("Start LogBack Load ...");
		LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
		System.out.println("[LogBack] Config File is " + logConfigFile);
		JoranConfigurator configurator = new JoranConfigurator();
		configurator.setContext(context);
		// Call context.reset() to clear any previous configuration, e.g. default 
	    // configuration. For multi-step configuration, omit calling context.reset().
		context.reset();
		try {
			configurator.doConfigure(logConfigFile);
		} catch (JoranException e) {
			StatusPrinter.printInCaseOfErrorsOrWarnings(context);
			System.out.println("[FATAL] Logback Init Exception, System Exit !!!");
			System.exit(-1);
		}
		System.out.println("LogBack Load End!");
	}
	
	private static Logger getOptLog(){
		return LoggerFactory.getLogger("bizLogger");
	}
	
	public static void vistLog(String logStr){
		getOptLog().warn(logStr);
	}
}

